/**
 * RoflkodeLexer.java
 * Authors: David Hara and Andrew Forney
 * CMSI 488 Assignment One
 * 
 * A simple token sequence parser for the
 * ROFLKODE language.
 */

import java.util.ArrayList;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.io.*;

public class RoflkodeLexer {

    // IT HAZ DA TOKENS
    static ArrayList<String> tokens = new ArrayList<String>();
	
    // DESE BE DA TOKEN TYPZ
    static final int PATTERNCOUNT = 9,    
    COMMENT = 0,
    STRLIT = 1,
    RESERVEDWORD = 2,
    SYMBOL = 3,
    NUMLIT = 4,
    INTLIT = 5,
    IDENTIFIER = 6,
    CHARLIT = 7,
    BREAK = 8;
    
    // WHAT LINEZ WE ON? START ON 1?! WTFBBQPWND!!!!11!!!1111!
    static int lineNum = 1;
    
    // WE PUTZ DA PATTERNS IN DIS BOX VVVVV THERE
    static Pattern[] patternArray = new Pattern[PATTERNCOUNT];
    
    /**
     * Main method used to iterate through the source and then
     * generate the token string.
     * @throws IOException
     */
    public static void main(String[] args) throws IOException {
        // IM IN YR INPUT... READIN YR LINEZ
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        
        // OK HAI START READING
        String line = input.readLine();
        
        // I GOTZ DA REGEXESESES LOOK DOWN VVVVVVV
        String patternCHAR = "[^\\p{Cc}\\x22\\x27:]|(:[)>\\x22':]|':('[0-9a-fA-F]{1,4}')')",
        patternIDENTIFIER = "\\p{L}[\\p{L}\\p{Nd}]*",
        patternBREAK = ",|[\\r\\n\\x85\\u2028\\u2029]",
        patternRESERVEDWORD = "(HAI|KTHXBYE|CAN|HAS|ITZ|4EVER|B00L"+
            "|KAR|INT|NUMBR|YARN|TEH|BULLOT|AKA"+
            "|CAN|MAEK|SRSLY|THEM|WIF|YR"+
            "|FACEPALM|PWNZOR|UPZORZ|NERFZORZ|GTFO"+
            "|HWGA|HEREZ|DIAF|GIMMEH|BRB|CEPT|WHIEL"+
            "|TIL|WERD|MEBBE|WAI|OIC"+
            "|OMGWTF|UPPIN|NERFIN|FROM|THRU"+
            "|OUTTA|PLZ|AWSUM|THX|NOES|MKAY|ORELSE"+
            "|ANALSO|BITOR|BITXOR|BITAND|CATN8|N00B|WIN"+
            "|FAIL|PWNS|PWNED|SAEM|DIVIDZ"+
            "|BITZLEFT|BITZRIGHT|UP|NERF|ITEMZ|OVR|LEFTOVR"+
            "|NAA|BITZFLIP|SIEZ|B00LZOR|INTZOR|NUMZOR"+
            "|KARZOR|YARNZOR|IM|IN|AN|YO|NO|IF|AS|OR|BY|R|UV" +
            "|WTF|OMG|A|I|O)(?=[^\\p{L}]|" + patternBREAK + ")",
        patternSYMBOL = "!!(!)?|\\?",
        patternINTLIT = "-?\\d+",
        patternNUMLIT = "-?\\d+\\.\\d+([Ee][+-]?\\d+)?",
        patternSTRLIT = "\\x22(" + patternCHAR + "|\\x27)*\\x22",
        patternCHARLIT = "\\x27(" + patternCHAR + "|\\x22)\\x27",
        patternCOMMENT = "BTW";
        
        // OK GOOD... GET DA ARRAY READY
        patternArray[IDENTIFIER] = Pattern.compile(patternIDENTIFIER);
        patternArray[RESERVEDWORD] = Pattern.compile(patternRESERVEDWORD);
        patternArray[SYMBOL] = Pattern.compile(patternSYMBOL);
        patternArray[NUMLIT] = Pattern.compile(patternNUMLIT);
        patternArray[INTLIT] = Pattern.compile(patternINTLIT);
        patternArray[STRLIT] = Pattern.compile(patternSTRLIT);
        patternArray[CHARLIT] = Pattern.compile(patternCHARLIT);
        patternArray[BREAK] = Pattern.compile(patternBREAK);
        patternArray[COMMENT] = Pattern.compile(patternCOMMENT);
        
        while (line != null) {
            // THE LINEZ... THEY NEED NEWLINES
            line = line + "\u2028";
            
            // GO GET DA TOKENZ... NAO!!!!111!!1!ELEVENTY!111!!1!!
            while (!line.equals("")) {
                line = tokenize(line);
            }
            
            // OR USE A GOTO AMIRITE? LOL
            line = input.readLine();
            lineNum++;
        }
        
        // IM EETING THE LAST LINEBREAK OMNOMNOMNOM
        tokens.remove(tokens.size() - 1);
        
        // OK I TELL YOU NAO...
        System.out.println(tokens);
    }
    
    /**
     * Helper function that parses the token sequence for a
     * given String. If there is an error in the parsed String,
     * it will throw an exception.
     */
    public static String tokenize(String input) {
        // THE SPACES BURNZ!!!11!!!1!! GOODBYE SPACES
        String s = input.trim();
        String foundToken;
        
        // TEH YARN'S NOT DER? SKIPZORZ!!!11!!1111!!!!!!1!
        if (s != null && !s.equals("")) {
            // I FIND TEH PATTERN NAO
            for (int patternType = 0; patternType < PATTERNCOUNT; patternType++) {
                Matcher m = patternArray[patternType].matcher(s);
                
                // WHERE DA MATCH AT? IN FRONT? OK.
                if (m.find() && m.start() == 0) {
                    foundToken = input.substring(m.start(), m.end());
                    switch (patternType) {
                        case COMMENT: return "";
                        case IDENTIFIER: tokens.add("ID(" + foundToken + ")"); break;
                        case INTLIT: tokens.add("INTLIT(" + foundToken + ")"); break;
                        case NUMLIT: tokens.add("NUMLIT(" + foundToken + ")"); break;
                        case STRLIT: tokens.add("STRLIT(" + foundToken + ")"); break;
                        case CHARLIT: tokens.add("CHARLIT(" + foundToken + ")"); break;
                        case BREAK: tokens.add("<BREAK>"); break;
                        default: tokens.add(foundToken); break;
                    }
                    // THE MATCHES! WE HAZ THEM
                    // DO TEH REST
                    return(input.substring(m.end()).trim());
                }
            }
        }
        
        // AN ERRORZ??!?! FIXITFIXITFIXIT! FIXITFIXIT!
        throw new IllegalArgumentException("\nNOOOOOEZ! SYNTAX ERROR @ LINEZ " + lineNum
                + "\n " + s
                + "\n^");
    }
    
}